package com.linkhub.oms.admin.modules.order.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import com.linkhub.oms.admin.modules.order.domain.param.OrderFulfillmentParam;
import com.linkhub.oms.admin.modules.order.domain.param.employee.*;
import com.linkhub.oms.admin.modules.order.domain.vo.EmployeeOrderForecastResultVO;
import com.linkhub.oms.admin.modules.order.domain.vo.EmployeeOrderPrintResultVO;
import com.linkhub.oms.admin.modules.order.domain.vo.EmployeeOrderPushToWmsResultVO;
import com.linkhub.oms.admin.modules.order.domain.vo.OrderTabCountVO;
import com.linkhub.oms.admin.modules.order.domain.vo.orderdetail.OrderDetailVO;
import com.linkhub.oms.admin.modules.order.domain.vo.orderlist.OrderlistVO;
import com.linkhub.oms.admin.modules.order.service.EmployeeOrderBizService;
import com.linkhub.oms.admin.modules.order.service.OrderInfoAssembleService;
import com.linkhub.oms.admin.modules.order.util.OrderMappingAssist;
import com.linkhub.oms.common.constant.RoleConstant;
import com.linkhub.oms.common.response.DataResponse;
import com.linkhub.oms.common.response.PageDTO;
import com.linkhub.oms.entity.resulttype.order.OrderInfoDO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @Description: 员工订单审核模块
 * @Author: echo
 * @Date: 2024/4/14 10:47
 * @Version: 1.0
 */
@Slf4j
@RestController
@Api(tags = {"员工订单审核模块"})
@RequestMapping("/order/employee")
@SaCheckLogin
@SaCheckRole(value = {RoleConstant.EMPLOYEE})
public class EmployeeOrderController {

    @Resource
    private EmployeeOrderBizService employeeOrderBizService;
    @Resource
    private OrderInfoAssembleService orderInfoAssembleService;

    @GetMapping("/list")
    @ApiOperation(value = "订单列表查询接口")
    public DataResponse<PageDTO<OrderlistVO>> pageCustomerOrders( @Validated EmployeeOrderQueryParam orderQueryParam ) {
        return DataResponse.success(employeeOrderBizService.pageOrders(orderQueryParam));
    }

    @GetMapping("/detail/{sysOrderId}")
    @ApiOperation(value = "订单详情接口")
    public DataResponse<OrderDetailVO> orderDetail( @PathVariable("sysOrderId") String sysOrderId ) {
        OrderInfoDO orderInfoDO = orderInfoAssembleService.assembleOrder(sysOrderId);
        return DataResponse.success(OrderMappingAssist.mappingOrderDetail(orderInfoDO));
    }

    @GetMapping("/tab/count")
    @ApiOperation(value = "订单页签数量接口")
    public DataResponse<List<OrderTabCountVO>> getTabOrderCount( @Validated EmployeeOrderCountQueryParam orderCountQueryParam ) {
        return DataResponse.success(employeeOrderBizService.queryOrderCount(orderCountQueryParam));
    }

    @PostMapping("/approvals")
    @ApiOperation(value = "员工审核接口")
    public DataResponse<Void> approvalOrders( @Valid @RequestBody EmployeeOrderApprovalParam orderApprovalParam ) {
        employeeOrderBizService.approvalOrders(orderApprovalParam);
        return DataResponse.success();
    }

    @PostMapping("/forecast")
    @ApiOperation(value = "员工预报接口")
    public DataResponse<EmployeeOrderForecastResultVO> forecastOrder( @Valid @RequestBody EmployeeOrderForecastParam employeeOrderForecastParam ) {
        return DataResponse.success(employeeOrderBizService.forecastOrder(employeeOrderForecastParam));
    }

    @PostMapping("/print")
    @ApiOperation(value = "员工打印接口")
    public DataResponse<EmployeeOrderPrintResultVO> printOrder( @Valid @RequestBody EmployeeOrderPrintParam employeeOrderPrintParam ) {
        return DataResponse.success(employeeOrderBizService.printOrder(employeeOrderPrintParam));
    }

    @PostMapping("/push_to_wms")
    @ApiOperation(value = "员工推送仓库接口")
    public DataResponse<EmployeeOrderPushToWmsResultVO> pushToWms( @Valid @RequestBody EmployeeOrderPushToWmsParam employeeOrderPushToWmsParam ) {
        return DataResponse.success(employeeOrderBizService.pushToWms(employeeOrderPushToWmsParam));
    }
}
